
#include <stdlib.h>
#include "Core/Log/LogManager.h"
#include "../Button/Button.h"
#include "../Layout/VerticalLayout.h"
#include "../Layout/HorizontalLayout.h"
//#include "../Layout/BoxLayout.h"
#include "Window.h"
#include "Application.h"

Application::Application(int argc, char *argv[])
: m_kit(argc, argv)
{
}

Application::~Application()
{

}

IWindow * Application::CreateWindow(const std::string & _strName, uint32 _iWidth, uint32 _iHeight)
{
	Window * pWindow = new Window(_strName);
	if (!pWindow->Create(_strName, _iWidth, _iHeight))
	{
		delete pWindow;
		return NULL;
	}
	m_WindowList.push_back(pWindow);
	return pWindow;
}

void Application::DestroyWindow(IWindow * _pWindow)
{
	if (_pWindow)
	{
		auto it = std::find(std::begin(m_WindowList), std::end(m_WindowList), _pWindow);
		if (it != std::end(m_WindowList))
		{
			m_WindowList.erase(it);
		}
		else
		{
			LOG_ERROR("Unknown window %s", _pWindow->GetName().c_str());
		}
		delete (Window*)_pWindow;
	}
}

IButton * Application::CreateButton(const std::string & _strName)
{
	return new Button(_strName);
}

void Application::DestroyButton(IButton * _pButton)
{
	delete (Button*)_pButton;
}

IVerticalLayout * Application::CreateVerticalLayout()
{
	return new VerticalLayout();
}

void Application::DestroyVerticalLayout(IVerticalLayout * _pVerticalLayout)
{
	delete (VerticalLayout*)_pVerticalLayout;
}

IHorizontalLayout * Application::CreateHorizontalLayout()
{
	return new HorizontalLayout();
}

void Application::DestroyHorizontalLayout(IHorizontalLayout * _pHorizontalLayout)
{
	delete (HorizontalLayout*)_pHorizontalLayout;
}

/*
IBoxLayout * Application::CreateBoxLayout()
{
	return new BoxLayout();
}

void Application::DestroyBoxLayout(IBoxLayout * _pBoxLayout)
{
	delete (BoxLayout*)_pBoxLayout;
}*/
